Some refactoring to accomodate QUnit testing