improvements to test code (thank you to @cstamas!)