Some fixes and refactoring for gestures.