I think this might read better as a for in loop, and it will be a bit faster too.