fix several bugs, but the position of cells are still not ok. Will fix later