More code cleanup, and added logging functionality