Updated solution for clarity