Refactored tests.js; simplified many things