Standalone refactoring

Merge back to master now that the refactoring is done