close out script - tide up code and refactoring