added tests & refactored. currently working