optimizations thanks to @mraleph