Fixes issue #50

All credit goes to https://github.com/lyokha