some optimisation for mem allocation