Updated SQL quries according to new db structure.