Refactored to make cleaner.