Corrects a bug
Cleans and documents a bit the code.