made major code changes to work with database.