Fixed a memory issues with factors