add touch function and simplify the codes