Updated Implementation

Refined logic