Add docs and fix error handling
Add missing docs and fix diagonals calculation code