Some bug fixes
- offset calculaition was not proper