reorganized and cleaned up test code