add functions for questions 6, 23, 39