Refactor code to increase the efficiency for a range greater than (1..15)