restructure code a bit to make more modular, add missing deps, add npm s...

i commented a bunch inline