Code for Radix Sort with optimizations