Lots of optimization changes to the DB