Fix bugs, add Flatten(), write sample calculator.