Cleanup and simplify code.