trying to fix the javascript function