If you go through that function and find stuff like this:
if (cts = true){
//always called as assignment returns true
}
if (cts = false){
//neve called as assignment returns true
}
It is wrong. It should be like this:
if (cts == true){
//called when cts is true
}
if (cts == false){
//called when cts is false
}
Can you see the difference?
Your code is using an assignment (set cts to equal true) which regardless of the math you do always returns true.
The second code block is using an equality operator - the statement is true if this IS EQUAL to that, else it is false.
For cases where you are checking if something is true or false, you are best using this:
if (cts){
//called when cts is true
}
if (!cts){
//called when cts is NOT true, i.e. false
}
This is important as when something returns true you can't guarantee that it is == to 0x01 (which is what true is defined as). In the world of C/C++, boolean true is anything which is not 0.