Optimized code some more, added scaling for masses.