Fixed bug causing NullPointerException