Refactor and cleanup.