Refactor fix_rev

It is not necessary to assign ~val to val.