Modified #2 to more elegant solution