Fix variable names and pass by ref