Fix for DB writes

EDIT: Arrgh, sorry.  Meant to do this for develop branch.  Please delete.


Hi,

3 Commits here.
1 and 2 are relatively minor (and 1 is already fixed in master)
3 is more of an issue, as it was preventing database writes.