improved; test: added, passes; needed refactoring