Fixing some simple issues.

refactor the complete function.

if ()
else if ()
else

with nothing makes no sense