Optimized the use of the hashmaps