Updated with the simplified logic