Updated to use stl Prime instead of homemade solution