Cleanig and refactoring the code