trimmed and refactored while porting to massive site