Refactored combined.py to make the whole big mess a big messy function which can be called from arcmap or as module from another python script.