ugly solution to problem 5 with failing tests