problem 12: some refactoring