Fix dimension order bug, add switch to use arraycopy and some code improvement.
Remove spurious "final" attributes.