DRYing up directory permission check into a separate module
minor stylistic edits