Added tests and solved some errors

Hi,

I've added some tests and fixes. It should work properly, at least for the php client.

Cheers,

Carles.

fixes #18