solution for problem #146