all codes from Dong Liang