fix the out of border bug