Fixed a variety of bugs after I was able to test this with actual data.
Fixed a variety of bugs after I was able to test this with actual data.

ubtue/ub_tools,ubtue/ub_tools,ubtue/ub_tools,ubtue/ub_tools,ubtue/ub_tools,ubtue/ub_tools,ubtue/ub_tools,ubtue/ub_tools