Fixed getting last number from history table