Cleanup and improved logging