Use functions instead of ifs