Refactor to increase modularity and readability.