lots of refactoring, and code hardening.  Also fixed bug in which dragend events were being fired before mouseup/touchend events