finished implementing invert function plus a new backup