Logging and Code cleanup