added touch event detection, and optimization