added comments and tweaked JS