Refactored edit handler.