clear before testing rather than after
many small fixes