Optimized all while loops