commented code and added unit tests for JS