some bug fix and test
Signed-off-by:Sergio L. <mellowonpsx@gmail.com>