Refactored problem 1

TODO: documentation