Fixed code so that it passes tests regardless of test run order