Added invertKey function