function[cleaned] = clean(a0, a1, a2, a3, a4, c1, c2, c3, c4)

% cleaning the results
% could maybe use mod function in this

% if a1<0 make a1 positive and push c1 half a phase. Same with a2,3,4
    
if a1<0
   a1 = -1*a1;
   c1 = c1+24;
end

if a2<0
   a2 = -1*a2;
   c2 = c2+12;
end

if a3<0
   a3 = -1*a3;
   c3 = c3+6;
end

if a4<0
   a4 = -1*a4;
   c4 = c4+4;
end

% if c<0, push a whole or 2 phase til it is positive.
    
while c1<0
    c1 = c1 + 48;
end

while c2<0
    c2 = c2 + 24;
end

while c3<0
    c3 = c3 + 12;
end

while c4<0
    c4 = c4 + 8;
end

% if c er over a phase, subtract a phase.

while c1>48
    c1 = c1 - 48;
end

while c2>24
    c2 = c2 - 24;
end

while c3>12
    c3 = c3 - 12;
end

while c4>8
    c4 = c4 - 8;
end

cleaned = [a0 a1 a2 a3 a4 c1 c2 c3 c4];

end
    