bug fix and better map edit logic