optimisation of hash, matrix