fixing variable assignment bug