fixes #139

Please review the code to confirm that it is the solution we need.