Reorganized code into server