Refactor state update API, better error handling

Filters; more 403s, fewer 500s; added logging; less duplication
Sending an invalid state value to add_correspondence now aborts the entire operation
whitespace

includes various code layout fixes