fixed bugs wrt loops and return objects