Added more NULL guards