make recursion optional
fix placement of hoisted declarations