Changed license to Apache License 2.0. Improved style and test coverage.