changed the script to a function