Function is now complete. See comments at bottom for other enhancements that can wait.