introduce back functionality and split up some JS

Still working on this, should be done by late next week!