Moved begin-rescue block to eliminate need for retry