adapting to encoding problems for any dimensions