pulled in some tweaks from @maurodx