improved the beforeTest function