Automatically calculate offset