Fix many bugs in the refactored server