reorganize and add sample function