Fixed reduce_inv
Code clean up
Code clean up