refactored, added tests, added to travis-ci