added test and did some refactoring