added detailed comments to javascript