Fixed error in calculate_overlap