Improved logging and fixed unit tests