Trying to fix a nullpointer bug but am unsucessfull