binary loops optimized