Code cleanup and refinements.