New version with an optional log-decrease threshold function