refactor - pulled various snippets from __main__ and made functions for them. Changed functions to use tuples as parameters. Changed references to "None" to use None.  The None reference needs to be tested as this may break a workaround for an issue in Ghost.