Add improved version using hash as the solution uses.