Added few check to javascript. Also cosmetic changes.