BUG: Correctly fix out of bounds access in MetaIO

This fixes a bug in commit 94752c44, and refactors the relevant
logic to be more maintainable.