cleanup directory code a bit