refactoring and cleanup from live code review