Refactoring server file.
Refactoring server code.