clean up #2 on JS

added comments and changed a couple of technique choices for clarity