refactor into modules with separate layers