Fix NULL pointer access