Move some code out of unsafe blocks.