Add checking for Cancel and remove unneeded code