refactor: refactor record and get smallest difference