refactor the server side