misc changes. added a pure PHP version