Problem 29:tweak with some refactoring