offset algorithm