Updated loop to support different coming-from configurations