Refactor based on the new data structure