added some comments on the main javascript method