Better handling of missing items

This solves #970 and possibly #638 (depending on what's remaining for that issue).