Fixed bug and nullpointer exception