Refactor some tests and classes