Refactor server scripts
Add tests for server files