Added checkIfValidFolder function and use it