Refactor and fix conceptual problems.