Refactor to use Eventmachine