Refactor and code cleanup.