Clean up and abstract code.