Fix for DB writes

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.