Refactor with more efficient ifs