added script cleaning logic