adding Factors helper. Problem3 is running as slow as you would expect given my approach. These factorization helpers should improve the performance immensely