incorporated @infinity0 patch, fixing issue #8