Refactored into autoload plugin, and reorganized code