Fixed substitute bug, rudimentary recursion