mostly done, need debug