Refactor server into some modules