Move var declaration inside ifblock.