Made filename vs directory logic more DRY