optimizations by @stof