Added comments. Basic JS code improvements.