Refactor

Reorganize the server side code