Improved code in previous commit. Will produce warnings, but they are ignorable.