suggested solution in #73 implemented as pull request

all credits to gabrielmaldi for work he linked in #73