moved a javascript function so it wouldn't be unnecessarily redefined