optimizing listallfiles method