Switch to table lookup to avoid repeat arithmetic