improvements pointed out by @tampakrap and @mgorny