Uses higherorder functions instead of for loops