Code cleanup, esp. in generate_db