Huge refactor for clarity and to make a single entry point for the framework