Fix #3091, fix bad var assignment