Refactoring and cleanup from code review