Need to refactor this into other modules, it seems a pretty common pattern.