Fix bug in the tests
Get the logic in the right order and fix variable naming (and run the tests)