Avoid record match in test mode (-s) and refactor a bit