revised codes and add javadocs