add unit test and fix offset