Added logic for measuring latencies