Fix some possible NULL access in an error case
Guard 2 peephole optimizations which should only work on the currently-last instruction by a check if it's actually really at the end...