fixed if else loop