copy codes from pos_v1
make the test pass