extend code for bigger dimensions