moved error handling into a helper. Updated templates to use helper.