Improved the modularity and clean the code