Minor optimizations and improvements to test command