More code refactoring and clean-up.