Refactor array handling

We do a lot of key lookups which should default or throw sensible
errors. Abstract this.