changing loop to be a bit more dynamic