Finished but using STL algorithmn