Fixed the bug in the original code
Renamed column-related variables
C -> currCOl
CC -> COLUMNS
removed obsolete variable WW
referred to as legacyInput where necessary