Changes inspired by @maffx