Improved patch for #23