cont rewrite: refactor into modules