   @type t :: %__MODULE__{channel: binary, channel_data: [{user_id, user_info}]}
 
   alias Poxa.PusherEvent
-  alias Poxa.Channel
+  import Poxa.Channel, only: [presence?: 1, subscribed?: 2]
   require Logger
 
   @doc """
   Returns a PresenceSubscription struct
   """
-  @spec subscribe!(binary, :jsx.json_term) :: PresenceSubscription.t
+  @spec subscribe!(binary, :jsx.json_term) :: __MODULE__.t
   def subscribe!(channel, channel_data) do
     decoded_channel_data = JSEX.decode!(channel_data)
-    if Channel.subscribed?(channel, self) do
+    if subscribed?(channel, self) do
       Logger.info "Already subscribed #{inspect self} on channel #{channel}"
     else
       Logger.info "Registering #{inspect self} to channel #{channel}"

    case :gproc.get_value({:p, :l, {:pusher, channel}}) do
      {user_id, _} ->
        if only_one_connection_on_user_id?(channel, user_id) do
          message = PusherEvent.presence_member_removed(channel, user_id)
          :gproc.send({:p, :l, {:pusher, channel}}, {self, message})
        end
      _ -> nil
    end


  @doc """
  This function checks if the user that is leaving the presence channel
  has more than one connection subscribed.

  If the connection is the only one, fire up the member_removed event
  """
  @spec check_and_remove :: :ok
  def check_and_remove do
    match = {{:p, :l, {:pusher, :'$1'}}, self, {:'$2', :_}}
    channel_user_id = :gproc.select([{match, [], [[:'$1',:'$2']]}])
    for [channel, user_id] <- channel_user_id,
      presence?(channel), only_one_connection_on_user_id?(channel, user_id) do
        presence_member_removed(channel, user_id)
    end
    :ok
  end

  defp presence_member_removed(channel, user_id) do
    message = PusherEvent.presence_member_removed(channel, user_id)
    :gproc.send({:p, :l, {:pusher, channel}}, {self, message})
  end

  defp only_one_connection_on_user_id?(channel, user_id) do
