This patch adds tests for some code paths we weren't hitting before and removes some dead code that couldn't be tested because it was unreachable.