implemented @astrofrog's suggested hack