patch for bug in last commit's optimization