Add error exit handling to 'function ..'