refactored dir_hash for readability