refactors core and middleware