Code Refactored to work faster