Final version with database