Updates after feedback (fixed a variable scope issue)