refactor edit button logic