refactor, and fix #10
this refactors things quite a bit to hopefully simplify the code base AND to facilitate fixing #10 (closed).
I tested this on my shift 6mq with unl0kr, and used diffoscope to verify that the files before and after this series were the same