fix all the last logic bugs