Fixed syntax, fully working if likely mathemically inefficient