Correct a few small bugs found with new test