Improved version of problem29