[#3357] Many many changes thanks to @WouterJ and @xabbuh