Clean up error handling; fix bug in attribution