A few random improvements to the database layer