Fixed the nullpointer exception