Add code documentation and tests