fix array access and change variable names according to the coding style