Fix a problem that return value None
add unit test
Add debug msgs