modularize js code, start adding tests