Document and beautify code