Last order fix
that is already defined

Codacy says it's defined on line 464. Codacy is wrong. Line 464 is part
of another function.
add else

Codacy complains about haveSentMessage being defined multiple times.
Change var name

Codacy doesn't like it. Aren't if blocks a separate scope?

"This problem can be harmful and should be avoided." <- please explain
this, Codacy.  You need to say why this is a problem.
Changed function names

I don't wanna change them, and you can't make me!
remove 'var'