Fix register saving code