Some fixes thanks to @stof