Code refactor to extract the different code to modules