server/main refactor