BinaryMatrix refactoring