Refactor

organize the server side code