refactory code and add sample code.