Putting in Qunit and tests (and fixed two bugs as a consequence).