Replaced huge function to use AlgorithmBacktrackSmartMemory