removed duplicated code for loops and scoped regions