applied patch from @hanspolo