Refactor code to client