Refactoring/small corrections to fix warnings from clang -fsanitize=undefined 'member call on null pointer'