Optimized the conditional swap code.