fixed some bugs in sphdem example