modify python code and make test unit