use joins instead of subqueries

for better mysql perf

sits on top of #28
ah yes, leftover from dev