More logging and code cleanup