Fix solution for problem 3

Re-write solution for problem 3 using template