July 18 2014, fixed tol=fix bug in writeOut function
July 24 2014, TF greedy working version 1