improving solution to prob1