improoved implementation and documentation of the code