Now working for multidimension input, created few new functions