Split out loading list of scripts to a function
Move unallocate loop to a function