test.js now works and refactor almost complete