code cleanup and redesign