Some minor code clean-up and refactoring