Fixed the problem when more than 8 bits.
Removing one dimension at a time and suming its values.