Incorporate script into function
Reindent script