Replace ifs with an array/loop