Fixed it to be constant time, needed else if instead of if.