Refactored for a simpler logic