General code review and clean up