Apply changes from alain91 for Issue #49