Minor code cleanup and refactor