Fixed some more bugs and tweaked testing code

(I couldn't stop myself from making changes this weekend.)