create and edit logic