Major refactor to make it compatible with ST3

Made it compatible with Sublime Text 3 (Python 3). It should work now in ST2 and ST3.

The refactor also separates the logic from the plugin extension points to make the implementation cleaner.