Fix some bugs and logincal function adjust