Refactored some core server code