refactoring: extracted methods; added test