fixed some if else and declaration bug