calculate entering and leaving vars