Improve generation of mutability checks