Remove Unused code.
fix possible buffer overflow.
code cleanup.