merged in most code from bzub/ProcessInputv2 and fixed various bugs