clean code

Removing redundant variable, redundant modifier, simplify conditions and unnecessary cast