added some checks to the JS