Try using a while instead of a when