Modified the logic