tweaks and fixes thanks to @Alint