Final Commit. Not tested in TC. Fixed buffer overflow.