refactor stage2, continue improving boilerplate