Cleanup. Exception handling. Added javadocs.