implemented new function calculate_overlap