fix formula parsing bugs, and other bugs