Restructure testing code