add error and close handler