Add more null pointer checks to text source