bsongen: handle nesting with unique var names