error handling

added some error handling functionality