code to find offset