Support for folders in flare imports and refactoring

Refactor code to improve reusability.
Support for folders in flare imports.
Fix bug with media imports that are in multiple pages.
Proper setting of order in flare import pages.