Refactoring patch from #58.