Added bound checking on left_or_right()