Update foreach to work with keys