Debugging: fixed incorrect variable scope