code clean up and documanetation