change from script into a function