Fixing bugs, adding phpunit tests

Signed-off-by: RJ garcia <rj@bighead.net>