cleaned up and added comments

also, fixed error when canceling search