Replaced fiddling with stream pos with proper attribute reading.