refactored folder logic