Added check for max traversal count and
typecheck for return statement