fix problem with if/else loop