Refactor to a more plug-in friendly architecture