Added in some error handling stuff