Minor code clean up and refactoring