added a bit of error handling