Bug fixes in deriving metadata offset