Reenstated code from #197 and #200.