Use functions instead of for loops