Added out of bounds check to IsLegalMove