refactor routing. add error-handling to client