refactoring bind/unbind algorithm