Refactor/simplify test process

- No need for global variables
- Less function calls