Added backtracking and updated calculation of metrics