Backporting tweaks from plasmiq.com