Minor changes
Changed function for reuseability. Ported another solution of  project euler