refactor to model after http module