refactored prob 12