Fix use-before-assignment bug