Add boundary check and reflection