fixed variable names, marked areas to be refactored