Moved and refactored SmartFolder code out of Brain