Code Refractorization and added functionalities