refactored to keep code cleaner