made factors.lua more efficient