cleanup of code
Added some documentation