fixing a boundary check problem