solution 46b - faster and simpler