Updated code to generate database