Fix master server and add unit tests.