code to calculate bug network vars