Added traps to cleanup on failure.