fix bugs, finalize, need test