Code clean up and optimization.