Fixed isValidPosition bug