ranges: use the ranges stored in the database properly(ish)