fix errors with nil pointers