Added invertBits function