Refactoring and small fix to calculating edge_dates