refactored a little code: tests still passed