Added in some error handling