major restructure of mapedit javascript