Refactor prob 3