`@items = Array(doc['items'] or doc)` will replace both those lines.