Change size calculation of rehashed hashmap and better memory management