added some basic error handling.