Various tweaks from gibbed.