code consolidation and cleanup