Re-implemented the logic