Fix errors in updatePosition function