rewrite touch focus algorithm