removed old implementation that only worked for input matrix of size nx2