ported from touchjs v0.2.13
fixed some code styles.