noticed i was calling sum() quite a bit, and only calling it once is an easy optimization