Refactor async code into client/server structures