Rewrote determinate to use non recursive algorythm.