Trying to fix null pointer exceptions