     Logger.debug "Received event #{inspect event}"
     if receiver == nil do
       # enqueue the event
-      new_q = :queue.in(q, event)
+      new_q = :queue.in(event, q)
       %__MODULE__{state | messages: new_q}
     else
       # send the event directly to the waiting process

    Logger.debug "State will be #{inspect state}"
    {:ok, state}
  end

  def handle_call({:hci_receive, [timeout]}, from, s = %__MODULE__{messages: q, receiver: nil}) do
    case :queue.out(q) do

  def terminate(reason, _state = %__MODULE__{port: port}) do
    Logger.debug("HCI is shutting down for reason: #{inspect reason}")
    # kill the port
    if (is_port(port)),
      do: Port.close(port),
    else: Process.exit(port, :normal)
    :ok
  end

