added "distinct" to some queries