code organization and cleanup