Small refactoring and testing