fixed bugs for non-multiples of 4