updated code. added documentation.