Simplified the logic