Fixed bug resulting from imperative-style for loop.