updated version with database