lastes code, still have some bugs for dragging edge