Fixed the tests by using a separate method which can be reused