revise for n>=1
calculate nrow(x)