fixes #1. Thanks to @lucadealfaro also if this is a rewrite of his initial patch