Check in improved R codes by Qi Zhang of Visual Heart Group