code cleanup and consolidation