working version for all questions,but slow