change logic for 1-d and 2-d