refactor into hapi plugin