Code improvements. Added some javaDocs.