Full refactor of core and router