changed naive clog2 implementation into more efficient.