edited script to check for isNaN