added last rule and modifications for loops