Minor refactors - moving variables into objects, code style, comment cleanup, etc
It's a draft because I have not tested it yet.
I consider the sugarcube syntax to be a a hate crime against Javascript, but a style guide is a style guide
Update: tested it for a bit, everything seems to be still working fine