Added check for invalid moves.