Refactored methods in server.py and improved testing