This is the actual DB query script. First version