Fix lots of issues with result of query() not being serializable