Started memory safety refactoring.