Code refactored to be able to be reused for another tasks