added safety checks for board and piece