Fixed version of pull request from MarcinListkowski

Changes that I think are necessary for inclusion