finished replace each blocks with detect statements