Cleaup and optimization.