Fix hosts iteration logic