implementation of https://mantis.phplist.com/view.php?id=17449