Code Refactoring and debugging