server cleanup & refactoring