cleanup and lots of bug fixes for inference; some of test suite passing