major refactoring and JavaDocs