refactoring
fix listdir behavior; optimizations