That ought to fix a few bugs, but I should write tests