applied fixes suggested by mailaender and pchote