Refactor to use a single data structure and only functions.