Fixing nullpointer exception