Changed the order of operations

This way it's a bit more forgiving and doesn't change a thing as far as the plugin and applications are concerned.

The change only applies to the cpp file, of course, I'm not sure why all the other files are being dragged in. Feel free to merge only what's relevant here.