improved: using fabulous work of @rouault