database and threading added