remove double-nested loop causing too many queries, fixes #10