first refactoring, added javadoc comments for classes and important methods.