added all the try and catch. Edit function.