Clean up and simplify code.