change license to BSD, small refactoring