Refactor into modules and wrapper.