add comments and improve documentation