Simplified some loops