Small refactoring and cleanup