Cleanup and improve unit tests