Refactor of code to allow for plugins