refactor obstacle condensation into a new function