Added first qunit tests. Passes headless test, but not 100% working in actual browsers
Manual merge. Deleted unused functions.