Refactors Java Server and adds some tests