refactoring and new edit function