     peer_data
   end
 
+  @spec loop_msgs(list(map()), TCPConn.t, PeerData.t)  :: PeerData.t
   def loop_msgs([msg | msgs], socket, peer_data) do
     new_peer_data = handle_message(msg.type, msg, socket, peer_data)
     loop_msgs(msgs, socket, new_peer_data)
   end
 
-  def loop_msgs(_, _, peer_data) do
+  def loop_msgs([], _, peer_data) do
     peer_data
   end
 

  require Bitwise
  require Logger
  require IEx
  alias BittorrentClient.Peer.Data, as: PeerData
  alias BittorrentClient.Peer.TorrentTrackingInfo, as: TorrentTrackingInfo
  alias BittorrentClient.Peer.Protocol, as: PeerProtocol

    {msgs, _} = PeerProtocol.decode(msg)
    {a_pd} = peer_data

    Logger.debug( "Messages #{inspect msgs} for #{inspect peer_data.peer_id}")
    ret = loop_msgs(msgs, socket, a_pd)
    # Logger.debug( "Returning this: #{inspect ret}")
    {:noreply, {ret}}
