refactored obstacle calculation