Reworked optimized as_hash