adding some more robust checking around inputs and outputs as well as other trivial fixes