Fix tax calculation bugs. Closes #1505 and #1554