add debugging, comments and documentation
fix doc