Vladimir V. Kolpakov contributed cleanup patch