syncrhonized demo code with nativer version