Extract loadFolders function.