Refactoring of issue #2