added functionality for nxn