     end
   end
 
-
-  defp broadcast_prev_frame(%{watched_frame_buffer: []} = state) do
+  defp broadcast_prev_frame(%{pos: pos} = state)
+  when pos <= 0 do
     state
   end
 

  require BattleSnake.Replay
  require Record

  defstruct([
    :frame_buffer,
    :watched_frame_buffer,
    :receiver,
    :replay_speed,
    :topic,
    state: :suspend
  ])


    attributes = Replay.row(row, :attributes)
    bin = Keyword.fetch!(attributes, :bin)
    recorder = :erlang.binary_to_term(bin)
    frames = recorder.frames
    topic = "replay:#{game_id}"
    replay_speed = 20
    init(topic, frames, replay_speed)
  end

  def init(topic, frames, replay_speed) do
    buffer = frames
    |> :array.from_list
    |> :array.fix

    new_state = struct(__MODULE__,
      topic: topic,
      replay_speed: replay_speed,
      size: :array.size(buffer),
      buffer: buffer
    )

    {:ok, new_state}
  end

