Fix handling of null references