Refactored to make code cleaner