little modification
adds tests
breaking down some methods