fixed one of many bugs causing NullPointerException