Refactor is_hash()