Fixing nested id bugs (#518; needs more testing)