lots of refactoring; less buggy but still needs more debugging for touch device support