complete implementation of edit