refactors code and add support for new tests