So far, the code has grown organically. We should refactor the code to reduce duplication and improve maintainability.