code cleanup some optimisation to chasing alg