Refactoring of the original code by Jose