Solution for problem #14