Refactoring and fix another instance of asan error