adapted to latest dev branch, minor code cleaning