mid refactor
a bit hacky, but refactor into main.js success!