Refactoring code and removing console logs