refactored boundary logic into single module