Add Debug flags for cmake - improve code style, fix potential buffer overflow on debug