Made directory creation for new files more robust