added a test and did some refactoring