Add copyright
Rewrite a bit of the algo