fixed and simplified JavaScript fixes #6