Fix bugs in generator refs and subdocs