Updated solution for C