Refactored code to seperate it from Koa, accept any app, any plugin