A bunch of quick fixes for the empty-db case

Don't crash if there is no data in the db.