Fixed some logic with primary key offset