relicensed, minor refactoring