fixed if else loop && errors