improved/fixed hash tree code