Fix many bugs, add new zend tests