Restructure test code a bit