fix bug with if logic