Improved logging and implemented test mode.