fix the yesterday bugs, and refactor the code