updated js script to work with new json response
refactoring