Updated solution for Justin.Yoo