6dc3aaa - The result of the DB query needs to be assigned to a variable.
334d961 - Use BETWEEN instead of two ranges, more likely to use index.
d785ac1 - Switch to ever-so-slightly quicker SQL.
99cce41 - Fetch divisions first, then loop through them in code, rather than one mammoth query.
35d6b2b - Use archive so that it doesn't refetch everything every time.