Move declarations out of foreach; Eliminate unnecessary var