final (working) version for problem 184