Optimized transpose and cleaned up a bit.