better folder test, cleanup some code