added bits and pieces from solution