Replace array for hash, optimizations