Updated to use foreach