added isIndexValid function and modified setPiece to an void