relicensed to apache license 2.0, minor code changes