Fix bugs and add sample