Removed 1 unnecessary level of cyclomatic complexity
Removed another unnessary level
Use pre-calculated cidx
Removed duplicate if/else