Fixed nullpointer exception that sometimes occured