Improved logging and debug