Refactoring: Move core functions outside of plugin class to make it easier to reuse in Processing plugin.