Cleaned up and refactored the code and separated the tests into another file, test.js.