made a few minor optimizations, moved calculations to initialization