Fix for null pointer exceptions