modified drag and drop function