Added commentary and simplified some jQuery.