Orm and db fixes