Improved logging, cleaned code.