Factor duplicated code into shared code.
Resolve copy/pasto after moving code to Database.pm.