Added a few error handling features