Clean up some testing code, minor optimizations