Some minor refactorings and clean ups