applied patch from porfirioribeiro, issue #1641