Breaking into functions and refactoring
Updating various things.  Broke function out to separate file, did various debugging.  Not sure if it is in a working state right now.