Massive refactor of application internals