added some error handling features