updated and fixed bug for offset