Started a small refactor of server side code and adding unit tests.