Problem 004 fix and refactor