Fix variable scoping issue in before block