Improved script for populating the database