Added action parameter in front of the options parameter. This will change things a little going forward, but most default configurations will still work. Adding comments, moving stash and unstash functions out of the loop so they're only defined once.