Major refactoring to represent keys as an array.