Fix infinish loop in dept calculation