Code cleanup and refinement.