Cleaned Server code into smaller code (for neatness)