refactoring and improving test coverage