replace ifs with endEditing method