Move read sector into separate function