Improved logging and tests