merged with latesest version of Tian's code. Failing 6-7 tests.