adds basic error checking function