Rework new and edit function