Merged changes from master branch. Modified Javascript to work for different versions.