Refactor to use GenServer