tidy ups to error handling