code refactor and new tests