replace while with fast enumeration