refactor script and rename to more appropriate to function