fixing possible null pointer exceptions