Refactors test code and add more tests