added support for loops
bug fix