updated and added js unit tests, also made slight refactorings and style changes