couple fixes and add phpunit test