Added a bit of error handling