Minor cleanup and refactoring