fixed potentially incorrect code (memcpy'ing overlapping regions).
code tweaks.