rearranged code to support unit tests, Travis, coveralls