fixed some bugs, adapted to Chi Square, integrated simple logger --- still very unclean